package com.belf.web.controller.console.group;

import com.belf.common.annotation.Log;
import com.belf.common.core.controller.BaseController;
import com.belf.common.core.domain.AjaxResult;
import com.belf.common.core.page.TableDataInfo;
import com.belf.common.enums.BusinessType;
import com.belf.common.utils.poi.ExcelUtil;
import com.belf.console.domain.DataBatchConf;
import com.belf.console.service.IDataBatchConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 批量同步配置Controller
 * 
 * @author belf
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/console/syncData")
public class DataBatchConfController extends BaseController
{
    @Autowired
    private IDataBatchConfService dataBatchConfService;

    /**
     * 查询批量同步配置列表
     */
    @PreAuthorize("@ss.hasPermi('console:batchConf:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataBatchConf dataBatchConf)
    {
        startPage();
        List<DataBatchConf> list = dataBatchConfService.selectDataBatchConfList(dataBatchConf);
        return getDataTable(list);
    }

    /**
     * 导出批量同步配置列表
     */
    @PreAuthorize("@ss.hasPermi('console:batchConf:export')")
    @Log(title = "批量同步配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataBatchConf dataBatchConf)
    {
        List<DataBatchConf> list = dataBatchConfService.selectDataBatchConfList(dataBatchConf);
        ExcelUtil<DataBatchConf> util = new ExcelUtil<DataBatchConf>(DataBatchConf.class);
        util.exportExcel(response, list, "批量同步配置数据");
    }

    /**
     * 获取批量同步配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('console:batchConf:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dataBatchConfService.selectDataBatchConfById(id));
    }

    /**
     * 新增批量同步配置
     */
    @PreAuthorize("@ss.hasPermi('console:batchConf:add')")
    @Log(title = "批量同步配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataBatchConf dataBatchConf)
    {
        return toAjax(dataBatchConfService.insertDataBatchConf(dataBatchConf));
    }

    /**
     * 新增SQL执行
     */
//    @Log(title = "SQL执行", businessType = BusinessType.UPDATE)
    @PostMapping("/push")
    @ResponseBody
    public AjaxResult pushLast(@RequestBody DataBatchConf dataBatchConf)
    {
        return dataBatchConfService.pushLast(dataBatchConf);
    }


    /**
     * 修改批量同步配置
     */
    @PreAuthorize("@ss.hasPermi('console:batchConf:edit')")
    @Log(title = "批量同步配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataBatchConf dataBatchConf)
    {
        return toAjax(dataBatchConfService.updateDataBatchConf(dataBatchConf));
    }

    /**
     * 删除批量同步配置
     */
    @PreAuthorize("@ss.hasPermi('console:batchConf:remove')")
    @Log(title = "批量同步配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dataBatchConfService.deleteDataBatchConfByIds(ids));
    }
}
